﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using BbsbWebService.Classes;
using System.Collections.ObjectModel;

namespace BbsbWebService.Repositories
{
    public abstract class RepositoryBase<T> where T : BaseItem
    {
        public ObservableCollection<T> Items = new ObservableCollection<T>();

        public abstract void SaveItem(T item);

        public abstract void RemoveItem(T item);

        public abstract void Initialise();

        public virtual XElement SaveRepository()
        {
            // Do nothing by default, only servers need to override this...
            return null;
        }

        public bool HasItem(Guid id)
        {
            return Items.Any(o => o.Id == id);
        }

        public T GetItem(Guid id)
        {
            return Items.Single(o => o.Id == id);
        }

        
    }
}
